package com.chuang.bootplus.controller.user;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.chuang.bootplus.base.exception.BusException;
import com.chuang.bootplus.base.utils.ApiResponse;
import com.chuang.bootplus.base.utils.HttpClientUtil;
import com.chuang.bootplus.base.utils.WechatGetUserInfoUtil;
import com.chuang.bootplus.entity.UserInfo;
import com.chuang.bootplus.po.bean.BeanSavePO;
import com.chuang.bootplus.po.WxLoginPO;
import com.chuang.bootplus.po.bean.BeanSelectPO;
import com.chuang.bootplus.service.UserInfoService;
import com.chuang.bootplus.vo.BeanListVO;
import com.chuang.bootplus.vo.BeanSelectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author lcc
 * @create 2021-07-14
 * @注意 本内容仅限于xinou内部传阅，禁止外泄以及用于其他的商业目的
 */
@RestController
@RequestMapping("user")
@Api(tags = {"用户中心"})
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserController {

    final UserInfoService userInfoService;
    private String appid="wx17233c2ae80c0c69";
    private String appSecret = "fe5b0d1b978e5859954dac2cfcdccb99";

    @ApiOperation("微信登陆")
    @PostMapping("loginByWx")
    public ApiResponse loginByWx(@RequestBody WxLoginPO po){
      return userInfoService.loginByWx(po);
    }

    @ApiOperation("碳豆增加")
    @PostMapping("saveBean")
    public ApiResponse<Void> saveBean(@RequestBody BeanSavePO po){
        return userInfoService.saveBean(po);
    }

    @ApiOperation("碳豆排名")
    @PostMapping("beanList")
    public ApiResponse<BeanListVO> beanList(){
        return userInfoService.beanList();
    }

    @ApiOperation("查询当前用户碳豆数量")
    @PostMapping("beanSelect")
    public ApiResponse<BeanSelectVO> beanSelect(@RequestBody BeanSelectPO po){
        return userInfoService.beanSelect(po);
    }

    @ApiOperation("保存用户信息")
    @PostMapping("saveUserInfo")
    public ApiResponse<Void> saveUserInfo(@RequestBody UserInfo po){
        return userInfoService.saveUserInfo(po);
    }
}
